/*
 * Powered By xTOOLs
 * Dev by DuRisk@pactera.com
 * Copyright © 2009 - 2017 pactera.com. All rights reserved.
 *
 * Generated at 2017年12月25日 10:52:48
 *
 */

package com.pactera.jep.service.sys.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.pactera.jep.autoconfigure.web.controller.BaseRestController;
import com.pactera.jep.core.exception.ServiceException;
import com.pactera.jep.orm.Filter;
import com.pactera.jep.orm.Order;
import com.pactera.jep.orm.Page;
import com.pactera.jep.sys.dto.MetaRegionTableNameDto;
import com.pactera.jep.sys.model.MetaRegion;
import com.pactera.jep.sys.model.MetaRegionTable;
import com.pactera.jep.sys.model.MetaTable;
import com.pactera.jep.sys.service.MetaRegionService;
import com.pactera.jep.sys.service.MetaRegionTableService;
import com.pactera.jep.sys.service.MetaTableService;
import com.pactera.jep.web.code.WebCode;
import com.pactera.jep.web.entity.BasicNameValuePair;
import com.pactera.jep.web.entity.NameValuePair;
import com.pactera.jep.web.util.RequestUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(value="元数据table管理")
@RestController
@RequestMapping("/metaRegionTable")
public class MetaRegionTablerRestController extends BaseRestController<MetaRegionTable> {
	private static Logger	logger	= LoggerFactory.getLogger(MetaRegionTablerRestController.class);

	@Autowired
	private MetaRegionTableService metaRegionTableService;

	/**
	 * 通过数据区域ID查询该区域ID对应的metaTable
	 * @return
	 */
	@GetMapping(
			value = {"/queryBusinessMetaTabe"},
			produces = {"application/json;charset=UTF-8"}
	)
	public Map<String, Object> queryBusinessMetaTabe(Model model, HttpServletRequest request, String roleCode){
		Map<String, Object> result = new HashMap<String, Object>();
		List<Filter> filters = RequestUtils.buildFilters(request);
		List<Order> orders = RequestUtils.buildOrders(request);
		List<MetaRegionTableNameDto> metaTables = metaRegionTableService.selectBusinessMetaTabe(filters, orders, roleCode);
		result.put(RESULT_TOTAL, metaTables.size());
		result.put(RESULT_ROWS, metaTables);
		return result;
	}

	/**
	 *
	 * @return
	 */
	@ApiOperation("通过数据区域ID查询该区域ID对应的metaTable")
	@GetMapping(
			value = {"/queryMetaRegionTableNameDto"},
			produces = {"application/json;charset=UTF-8"}
	)
	public Map<String, Object> queryMetaRegionTableNameDto(Page<MetaRegionTableNameDto> page, String regionId, String tableCode, String tableName) {
		Map<String, Object> result = new HashMap();
		metaRegionTableService.queryMetaRegionTableNameDto(page, regionId, tableCode, tableName);
		result.put("total", page.getTotal());
		result.put("rows", page.getResult());
		return result;
	}

}